package com.cjzuji.rental.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjzuji.rental.mapper.OrderMapper;
import com.cjzuji.rental.mapper.RequestMapper;
import com.cjzuji.rental.pojo.RequestHeard;
import com.cjzuji.rental.service.XWuService;
import com.cjzuji.rental.service.YouPinService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 获取X物详情
 * @date 2025/9/29
 */
@RestController
@RequestMapping("/order/xwu")
@Api(tags = "X物订单列表")
//@Component
public class XWuController {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RequestMapper requestMapper;
    @Autowired
    XWuService xWuService;

    private static final Logger logger = LoggerFactory.getLogger(XWuController.class);
    //http://127.0.0.1:9099/order/xwu/getListInfo
    //获取所有数据
    @GetMapping("/getListInfo")
    @ApiOperation(value = "获取X物订单列表详情", notes = "X物所有订单列表和订单详情")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    public List<Map<String, Object>> getOrderList(){
        //从数据库获取
        try{
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String token = requestHeard.getXwutoken();
            logger.info("获取X物token: {}",token);
            String cookie = requestHeard.getXwucookie();
            String randomCode = requestHeard.getXwurandomCode();
            List<Map<String, Object>> result = xWuService.getOrdersList(token, cookie, randomCode);
            return result;
        }catch (Exception e){
            logger.error("获取 X物 所有订单列表详情失败");
            return null;
        }
    }
}
